package org.farm2.ai.test.client;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingModel;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingOptions;
import org.farm2.ai.test.config.ApiConfig;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;

import java.net.MalformedURLException;
import java.util.List;

public class EmbeddingDemo {
    public static void main(String[] args) throws MalformedURLException {
        getClient();
    }

    private static final String AUDIO_RESOURCES_URL = "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav";


    public static void getClient() throws MalformedURLException {
        String apiKey = ApiConfig.apiKey;
        DashScopeApi dashScopeApi = new DashScopeApi(apiKey);
        DashScopeEmbeddingModel model = new DashScopeEmbeddingModel(dashScopeApi);


        EmbeddingResponse embeddingResponse = model.call(
                new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"),
                        DashScopeEmbeddingOptions.builder()
                                .withModel("text-embedding-v4")
                                .build()));

        System.out.println(embeddingResponse.getResult().getOutput().length);
    }


}
